﻿using System;

public class GlobalMembersGame_AI  : GlobalMembersGame_object
{

	internal static LCUI_BOOL PlayerCanChangeOriented(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_READY:
		case GamePlayerState.STATE_STANCE:
		case GamePlayerState.STATE_WALK:
		case GamePlayerState.STATE_JUMP:
		case GamePlayerState.STATE_FALL:
		case GamePlayerState.STATE_SQUAT:
		case GamePlayerState.STATE_SSQUAT:
		case GamePlayerState.STATE_JUMP_DONE:
		case GamePlayerState.STATE_BE_LIFT_STANCE:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL ICanAction(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_READY:
		case GamePlayerState.STATE_STANCE:
		case GamePlayerState.STATE_WALK:
		case GamePlayerState.STATE_JUMP:
		case GamePlayerState.STATE_FALL:
		case GamePlayerState.STATE_BE_LIFT_STANCE:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL PlayerCanReady(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_READY:
		case GamePlayerState.STATE_STANCE:
		case GamePlayerState.STATE_WALK:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL TargetCanAction(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_LYING:
		case GamePlayerState.STATE_TUMMY:
		case GamePlayerState.STATE_LYING_HIT:
		case GamePlayerState.STATE_TUMMY_HIT:
		case GamePlayerState.STATE_REST:
		case GamePlayerState.STATE_JUMP:
		case GamePlayerState.STATE_SJUMP:
		case GamePlayerState.STATE_SQUAT:
		case GamePlayerState.STATE_SSQUAT:
		case GamePlayerState.STATE_JUMP_DONE:
			return FALSE;
		default:
			break;
		}
		return TRUE;
	}

	internal static LCUI_BOOL TargetIsRest(int state)
	{
		if(state == (int)GamePlayerState.STATE_REST)
		{
			return TRUE;
		}
		return FALSE;
	}

	internal static LCUI_BOOL IAmJumpDone(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_JUMP_DONE:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL IAmRunning(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_LEFTRUN:
		case GamePlayerState.STATE_RIGHTRUN:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL IAmSJump(int state)
	{
		if(state == (int)GamePlayerState.STATE_SJUMP)
		{
			return TRUE;
		}
		return FALSE;
	}

	internal static LCUI_BOOL PlayerWillSprintJumpAttack(int state)
	{
		if(state == (int)GamePlayerState.STATE_SJUMP || state == (int)GamePlayerState.STATE_ASJ_ATTACK || state == (int)GamePlayerState.STATE_BSJ_ATTACK)
		{
			return TRUE;
		}
		return FALSE;
	}

	internal static LCUI_BOOL PlayerWillSpecialAttack(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_BOMBKICK:
		case GamePlayerState.STATE_SPINHIT:
		case GamePlayerState.STATE_BIG_ELBOW:
		case GamePlayerState.STATE_GUILLOTINE:
		case GamePlayerState.STATE_KICK:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL PlayerWillNormalAttack(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_AJ_ATTACK:
		case GamePlayerState.STATE_BJ_ATTACK:
		case GamePlayerState.STATE_A_ATTACK:
		case GamePlayerState.STATE_B_ATTACK:
		case GamePlayerState.STATE_MACH_A_ATTACK:
		case GamePlayerState.STATE_MACH_B_ATTACK:
		case GamePlayerState.STATE_FINAL_BLOW:
		case GamePlayerState.STATE_JUMP_ELBOW:
		case GamePlayerState.STATE_JUMP_STOMP:
		case GamePlayerState.STATE_MACH_STOMP:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL PlayerWillSprintAttack(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_AS_ATTACK:
		case GamePlayerState.STATE_BS_ATTACK:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL ICanCloseTarget(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_READY:
		case GamePlayerState.STATE_STANCE:
		case GamePlayerState.STATE_WALK:
		case GamePlayerState.STATE_LEFTRUN:
		case GamePlayerState.STATE_RIGHTRUN:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL ICatchTarget(int state)
	{
		if(state == (int)GamePlayerState.STATE_CATCH)
		{
			return TRUE;
		}
		return FALSE;
	}

	internal static LCUI_BOOL ILifeTarget(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_LIFT_STANCE:
		case GamePlayerState.STATE_LIFT_FALL:
		case GamePlayerState.STATE_LIFT_JUMP:
		case GamePlayerState.STATE_LIFT_RUN:
		case GamePlayerState.STATE_LIFT_WALK:
			return TRUE;
		default:
			break;
		}
		return FALSE;
	}

	internal static LCUI_BOOL TargetIsLying(int state)
	{
		switch((GamePlayerState)state)
		{
		case GamePlayerState.STATE_LYING:
		case GamePlayerState.STATE_TUMMY:
		case GamePlayerState.STATE_LYING_HIT:
		case GamePlayerState.STATE_TUMMY_HIT:
			return TRUE;
		}
		return FALSE;
	}

	internal static LCUI_BOOL IAmRide(int state)
	{
		if(state == (int)GamePlayerState.STATE_RIDE)
		{
			return TRUE;
		}
		return FALSE;
	}
    public static LCUI_BOOL FALSE=false;
    public static LCUI_BOOL TRUE=true;


    //C++ TO C# CONVERTER NOTE: Embedded comments are not maintained by C++ to C# Converter
    //ORIGINAL LINE: static AIStrategy global_strategy_set[MAX_STRATEGY_NUM] = { { 0, /* 距离在0-50的范围内，目标将要进行普通攻击，则进行防御 */ ICanAction, PlayerWillNormalAttack, {0,50,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_defense), new AIActionData_( TRUE, 0, ai_action_type_stop_defense), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-80的范围内，目标将要进行冲撞攻击，则进行防御 */ ICanAction, PlayerWillSprintAttack, {0,80,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_defense), new AIActionData_( TRUE, 0, ai_action_type_stop_defense), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-100的范围内，目标将要进行冲刺跳跃攻击，则进行防御 */ ICanAction, PlayerWillSprintJumpAttack, {0,100,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_defense), new AIActionData_( TRUE, 0, ai_action_type_stop_defense), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-50的范围内，目标将要进行特殊攻击，则进行防御 */ ICanAction, PlayerWillSpecialAttack, {0,50,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_defense), new AIActionData_( TRUE, 0, ai_action_type_stop_defense), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-55的范围内，对目标进行A攻击 */ ICanAction, TargetCanAction, {0,55,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在25-40的范围内，目标躺地，对目标进行A攻击 */ ICanAction, TargetIsLying, {25,40,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}),{ 0, /* 距离在0-55的范围内，对目标进行B攻击 */ ICanAction, NULL, {0,55,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-55的范围内，目标处于喘气状态，跳跃+攻击目标 */ ICanAction, TargetIsRest, {0,55,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_jump), new AIActionData_( TRUE, 0, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-55的范围内，目标处于喘气状态，攻击目标 */ ICanAction, TargetIsRest, {0,55,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-55的范围内，目标处于喘气状态，站着观察 */ ICanAction, TargetIsRest, {0,55,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 300, ai_action_type_observe), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-55的范围内，目标处于喘气状态，靠近他 */ ICanAction, TargetIsRest, {0,55,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_walk_close), new AIActionData_(FALSE, 0, ai_action_type_none)}), new AIStrategy_( 0, ICanAction, TargetIsLying, {10,55,0,RANGE_MAX}, new AIActionData_[]{ new AIActionData_( TRUE, 100, ai_action_type_walk_close), new AIActionData_(FALSE, 0, ai_action_type_none)}), new AIStrategy_( 0, ICanAction, TargetIsLying, {0,10,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), new AIStrategy_( 0, ICanAction, TargetIsLying, {0,10,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_down), new AIActionData_(FALSE, 0, ai_action_type_none)}), new AIStrategy_( 0, IAmRide, TargetIsLying, {0,10,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), new AIStrategy_( 0, IAmRide, TargetIsLying, {0,10,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-20的范围内，步行远离目标 */ ICanAction, TargetCanAction, {0,20,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_walk_away), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-40的范围内，跑步远离目标 */ ICanAction, TargetCanAction, {0,40,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 300, ai_action_type_run_away), new AIActionData_( TRUE, 50, ai_action_type_stop_run), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在150以上的范围内，跑步靠近目标 */ ICanCloseTarget, NULL, {150,RANGE_MAX,0,RANGE_MAX}, new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_run_close), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 跳跃落地时，若目标在攻击范围内，则使用自旋击 */ IAmJumpDone, NULL, {20,400,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 100, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 跳跃落地时，若目标在攻击范围内，则使用爆裂腿 */ IAmJumpDone, NULL, {20,400,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 100, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 跳跃落地后，观察目标 */ IAmJumpDone, NULL, {20,400,0,RANGE_MAX}, new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_observe), new AIActionData_(FALSE, 0, ai_action_type_none)}), new AIStrategy_( 0, ICanCloseTarget, TargetCanAction, {65,80,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 0, ai_action_type_run_close), new AIActionData_( TRUE, 100, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), new AIStrategy_( 0, ICanCloseTarget, NULL, {65,80,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 0, ai_action_type_run_close), new AIActionData_( TRUE, 100, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在10至150的范围内，处于跑步状态，使用冲刺A攻击 */ IAmRunning, TargetCanAction, {10,150,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 100, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在10至150的范围内，处于跑步状态，使用冲刺B攻击 */ IAmRunning, NULL, {10,150,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 100, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离500以上，观察目标 */ ICanAction, TargetCanAction, {500,RANGE_MAX,0,RANGE_MAX}, new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_observe), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在0-150的范围内，步行靠近目标 */ ICanAction, NULL, {0,150,0,RANGE_MAX}, new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_walk_close), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在200-300的范围内，进行跳跃 */ IAmRunning, NULL, {200,300,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 0, ai_action_type_jump), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在200-300的范围内，进行跳跃+A攻击 */ IAmRunning, TargetCanAction, {200,300,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_jump), new AIActionData_( TRUE, 50, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在200-300的范围内，进行跳跃+B攻击 */ IAmRunning, NULL, {200,300,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_jump), new AIActionData_( TRUE, 50, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在20-150的范围内，自己处于奔跑后的跃起状态，进行A攻击 */ IAmSJump, TargetCanAction, {20,150,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在20-150的范围内，自己处于奔跑后的跃起状态，进行B攻击 */ IAmSJump, NULL, {20,150,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}),{ 0, /* 距离在20-300的范围内，对方若要进行跳跃攻击，跑步远离 */ ICanAction, PlayerWillSprintJumpAttack, {20,300,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 200, ai_action_type_run_away), new AIActionData_( TRUE, 50, ai_action_type_stop_run), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 距离在350-420的范围内，进行跳跃，并使用高挑旋转落体 */ IAmRunning, NULL, {350,420,0,GLOBAL_Y_WIDTH/2-2), new AIActionData_[]{ new AIActionData_( TRUE, 50, ai_action_type_jump), new AIActionData_( TRUE, 200, ai_action_type_down), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 如果自己擒住了一个目标，则使用A攻击 */ ICatchTarget, NULL, {0,RANGE_MAX,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_wait), new AIActionData_( TRUE, 500, ai_action_type_a_attack), new AIActionData_( TRUE, 500, ai_action_type_observe), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 如果自己擒住了一个目标，则使用B攻击 */ ICatchTarget, NULL, {0,RANGE_MAX,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_wait), new AIActionData_( TRUE, 200, ai_action_type_b_attack), new AIActionData_( TRUE, 500, ai_action_type_observe), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 如果自己举起了一个目标，则抛掷出去 */ ILifeTarget, NULL, {0,RANGE_MAX,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_wait), new AIActionData_( TRUE, 500, ai_action_type_a_attack), new AIActionData_(FALSE, 0, ai_action_type_none)}), { 0, /* 如果自己举起了一个目标，则往下摔 */ ILifeTarget, NULL, {0,RANGE_MAX,0,GLOBAL_Y_WIDTH), new AIActionData_[]{ new AIActionData_( TRUE, 500, ai_action_type_wait), new AIActionData_( TRUE, 500, ai_action_type_b_attack), new AIActionData_(FALSE, 0, ai_action_type_none} } } };
    internal static AIStrategy_[] global_strategy_set = {
        new AIStrategy_( 0, ICanAction, PlayerWillNormalAttack, new DistanceRange_(0,50,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_defense),
                new AIActionData_( TRUE, 0, (int)AIActionType.ai_action_type_stop_defense),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, PlayerWillSprintAttack, new DistanceRange_(0,80,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_defense),
                new AIActionData_( TRUE, 0, (int)AIActionType.ai_action_type_stop_defense),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, PlayerWillSprintJumpAttack, new DistanceRange_(0,100,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_defense),
                new AIActionData_( TRUE, 0, (int)AIActionType.ai_action_type_stop_defense),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, PlayerWillSpecialAttack, new DistanceRange_(0,50,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_defense),
                new AIActionData_( TRUE, 0, (int)AIActionType.ai_action_type_stop_defense),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetCanAction, new DistanceRange_(0,55,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetIsLying, new DistanceRange_(25,40,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, null, new DistanceRange_(0,55,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetIsRest, new DistanceRange_(0,55,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_jump),
                new AIActionData_( TRUE, 0, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetIsRest, new DistanceRange_(0,55,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetIsRest, new DistanceRange_(0,55,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 300, (int)AIActionType.ai_action_type_observe),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetIsRest, new DistanceRange_(0,55,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_walk_close),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetIsLying, new DistanceRange_(10,55,0,-1),
            new AIActionData_[]{ new AIActionData_( TRUE, 100, (int)AIActionType.ai_action_type_walk_close),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetIsLying, new DistanceRange_(0,10,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetIsLying, new DistanceRange_(0,10,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_down),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmRide, TargetIsLying, new DistanceRange_(0,10,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmRide, TargetIsLying, new DistanceRange_(0,10,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetCanAction, new DistanceRange_(0,20,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_walk_away),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetCanAction, new DistanceRange_(0,40,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 300, (int)AIActionType.ai_action_type_run_away),
                new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_stop_run),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanCloseTarget, null, new DistanceRange_(150,-1,0,-1),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_run_close),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmJumpDone, null, new DistanceRange_(20,400,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 100, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmJumpDone, null, new DistanceRange_(20,400,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 100, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmJumpDone, null, new DistanceRange_(20,400,0,-1),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_observe),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanCloseTarget, TargetCanAction, new DistanceRange_(65,80,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 0, (int)AIActionType.ai_action_type_run_close),
                new AIActionData_( TRUE, 100, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanCloseTarget, null, new DistanceRange_(65,80,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 0, (int)AIActionType.ai_action_type_run_close),
                new AIActionData_( TRUE, 100, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmRunning, TargetCanAction, new DistanceRange_(10,150,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 100, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmRunning, null, new DistanceRange_(10,150,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 100, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, TargetCanAction, new DistanceRange_(500,-1,0,-1),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_observe),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, null, new DistanceRange_(0,150,0,-1),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_walk_close),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmRunning, null, new DistanceRange_(200,300,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 0, (int)AIActionType.ai_action_type_jump),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmRunning, TargetCanAction, new DistanceRange_(200,300,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_jump),
                new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmRunning, null,new DistanceRange_(200,300,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_jump),
                new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmSJump, TargetCanAction, new DistanceRange_(20,150,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmSJump, null, new DistanceRange_(20,150,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICanAction, PlayerWillSprintJumpAttack, new DistanceRange_(20,300,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_run_away),
                new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_stop_run),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, IAmRunning, null, new DistanceRange_(350,420,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH/2-2),
            new AIActionData_[]{ new AIActionData_( TRUE, 50, (int)AIActionType.ai_action_type_jump),
                new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_down),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICatchTarget, null, new DistanceRange_(0,-1,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_wait),
                new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_observe),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ICatchTarget, null, new DistanceRange_(0,-1,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_wait),
                new AIActionData_( TRUE, 200, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_observe),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ILifeTarget, null, new DistanceRange_(0,-1,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_wait),
                new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_a_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none)}),
        new AIStrategy_( 0, ILifeTarget, null, new DistanceRange_(0,-1,0,DefineConstantsGame_AI.GLOBAL_Y_WIDTH),
            new AIActionData_[]{ new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_wait),
                new AIActionData_( TRUE, 500, (int)AIActionType.ai_action_type_b_attack),
                new AIActionData_(FALSE, 0, (int)AIActionType.ai_action_type_none) })} ;

    ////* 获取自己的攻击目标 
    internal static GamePlayer_ GamePlayer_GetTarget(GamePlayer_ self)
    {
        int id;
        int i;
        GamePlayer_ player;
        if (LCUI_GetTickCount() < self.ai_data.target_update_time)
        {
            player = GameBattle_GetPlayer(self.battle_id, self.ai_data.target_id);
            if (player != null && player.enable && player.state != (int)GamePlayerState.STATE_DIED && player.state != (int)GamePlayerState.STATE_LYING_DYING && player.state != (int)GamePlayerState.STATE_TUMMY_DYING)
            {
                return player;
            }
        }
        self.ai_data.target_update_time = LCUI_GetTickCount() + 10000;
        // 最多重选10次目标 
        for (i = 0; i < 10; ++i)
        {
            id = RandomNumbers.NextNumber() % 4 + 1;
            if (id != self.id)
            {
                self.ai_data.target_id = id;
                player = GameBattle_GetPlayer(self.battle_id, id);
                if (player == null || !player.enable || player.state == (int)GamePlayerState.STATE_DIED || player.state == (int)GamePlayerState.STATE_LYING_DYING || player.state == (int)GamePlayerState.STATE_TUMMY_DYING)
                {
                    continue;
                }
                return player;
            }
        }
        return null;
    }

    ////* 获取自己与对方的距离 
    internal static LCUI_BOOL GamePlayer_GetDistance(GamePlayer_ self, GamePlayer_ target, ref int x_width, ref int y_width)
    {
        if (self == null || target == null || self.object_ == null || target.object_ == null)
        {
            return FALSE;
        }
        x_width = (int)GameObject_GetX(self.object_);
        x_width -= (int)GameObject_GetX(target.object_);
        y_width = (int)GameObject_GetY(self.object_);
        y_width -= (int)GameObject_GetY(target.object_);
        return TRUE;
    }

    ////******************************************************************************
    ////假设有A、B、C三个随机事件，概率分别为：0.95,、0.045、0.005，随机情况如下：
    ////
    ////随机次数		20			200
    ////-------------------------------------------------------------
    ////随机事件
    ////A，0.95，1.05：
    ////		20/1.05 = 19.05		200/1.05 = 190.48
    ////		19.05 - 19 = 0.05	190.48 - 190 = 0.48
    ////B，0.045，22.22：
    ////		20/22.22 =0.90		200/22.22 = 9.0009
    ////		0.90 - 0 = 0.90		9.0009 - 9 = 0.0009
    ////C，0.005，200：
    ////		20/200 = 0.1		200/200 = 1
    ////		0.1 - 0 = 0.1		1 - 1 = 0
    ////随机结果：
    ////		A事件可能会出现		C事件可能会出现
    ////******************************************************************************

    ////* 从若干个随机想法中选择一个想法 
    internal static int RandIdea_Select(RandIdea_[] ideas, int n_idea)
    {
        int[] idea_pos;
        double[] idea_amount;
        double avg;
        int i;
        int j;
        int num;
        int total_amount;
        int val;

        if (n_idea < 1)
        {
            return -1;
        }
        idea_amount = new double[n_idea];
        idea_pos= new int[n_idea];
        num = RandomNumbers.NextNumber() % 10000;
        total_amount = 10000;
        //C++ TO C# CONVERTER TODO TASK: The memory management function 'malloc' has no equivalent in C#:
        //		idea_amount = (double)malloc(n_idea *typeof(double));
        //		if (idea_amount == 0)
        //		{
        //			return -2;
        //		}
        ////C++ TO C# CONVERTER TODO TASK: The memory management function 'malloc' has no equivalent in C#:
        //		idea_pos = (int)malloc(n_idea *typeof(int));
        //		if (idea_pos == 0)
        //		{
        //			return -3;
        //		}
        for (avg = 0, i = 0; i < n_idea; ++i)
        {
            if (ideas[i].probability > total_amount)
            {
                ideas[i].probability = total_amount;
            }
            total_amount -= ideas[i].probability;
            idea_amount[i] = 1.0 * num * ideas[i].probability / 10000;
            val = (int)idea_amount[i];
            idea_amount[i] -= val;
            avg += idea_amount[i];
        }
        avg = avg / n_idea;
        for (j = 0, i = 0; i < n_idea; ++i)
        {
            // 如果小于平均概率，则记录该想法的下标 
            if (idea_amount[i] <= avg)
            {
                idea_pos[j] = i;
                ++j;
            }
        }
        // 返回被随机选中的想法的ID 
        return ideas[idea_pos[RandomNumbers.NextNumber() % j]].id;
        //return ideas[UnityEngine.Random.Range(0, ideas.Length)].id;
    }

    ////* 初始化游戏AI 
    public static void GameAI_Init()
    {
        RandomNumbers.Seed((int)time(null));
    }

    public static LCUI_BOOL StrategyActionIsTimeOut(GameAI_Data_ p_data)
    {
        int cur_time = new int();
        uint diff_val;
        AIStrategy_ p_strategy;

        // 若动作序号超出有效范围 
        if (p_data.action_num >= DefineConstantsGame_AI.MAX_ACTION_NUM)
        {
            return TRUE;
        }
        p_strategy = global_strategy_set[p_data.strategy_id];
        // 若该动作并没有启用 
        if (!p_strategy.action[p_data.action_num].enable)
        {
            return TRUE;
        }
        cur_time = LCUI_GetTickCount();
        diff_val = (uint)(cur_time - p_data.start_time);
        // 若该动作的停留时间超出时限 
        if (diff_val >= p_strategy.action[p_data.action_num].time)
        {
            return TRUE;
        }
        return FALSE;
    }

    ////* 检测当前策略是否有效 
    public static LCUI_BOOL StrategyIsValid(GameAI_Data_ p_data, int target_state, int x_width, int y_width)
    {
        int n_last_action;
        AIStrategy_ p_strategy;

        // 若策略ID超出有效范围 
        if (p_data.strategy_id < 0 && p_data.strategy_id >= DefineConstantsGame_AI.MAX_STRATEGY_NUM)
        {
            return FALSE;
        }
        p_strategy = global_strategy_set[p_data.strategy_id];
        for (n_last_action = 0; n_last_action < DefineConstantsGame_AI.MAX_ACTION_NUM; ++n_last_action)
        {
            if (!p_strategy.action[n_last_action].enable)
            {
                if (n_last_action > 0)
                {
                    --n_last_action;
                }
                break;
            }
        }
        // 如果这是最后一个动作，则检测该动作是否超时 
        if (p_data.action_num == n_last_action)
        {
            return !StrategyActionIsTimeOut(p_data);
        }
        else if (p_data.action_num > n_last_action)
        {
            return FALSE;
        }
        return TRUE;
    }

    ////* 按条件过滤策略，并获取符合条件的策略ID 
    public static int FilterStrategy(int[] strategy_buff, int max_num, int self_state, int target_state, int x_width, int y_width)
    {
        int i=0;
        int j=0;
        // 自己死了或者目标死了，那就没策略了 
        if (self_state == (int)GamePlayerState.STATE_DIED || target_state == (int)GamePlayerState.STATE_DIED)
        {
            return 0;
        }
        // 取距离的绝对值 
        if (x_width < 0)
        {
            x_width = 0 - x_width;
        }
        if (y_width < 0)
        {
            y_width = 0 - y_width;
        }
        DEBUG_MSG("[%d], y_width: %d, max: %d\n", i, y_width, global_strategy_set[i].range.max_y_width);
        // 遍历查找符合条件的策略 
        for (j = 0, i = 0; i < DefineConstantsGame_AI.MAX_STRATEGY_NUM; ++i)
        {
            // 判断状态是否符合要求 
            if (global_strategy_set[i].self_state!=null)
            {
                if (!global_strategy_set[i].self_state(self_state))
                {
                    continue;
                    ;
                }
            }
            if (global_strategy_set[i].target_state!=null)
            {
                if (!global_strategy_set[i].target_state(target_state))
                {
                    continue;
                    ;
                }
            }
            // 判断与目标的距离是否符合要求 
            if (x_width < global_strategy_set[i].range.min_x_width)
            {
                continue;
            }
            if (global_strategy_set[i].range.max_x_width != -1)
            {
                if (x_width >= global_strategy_set[i].range.max_x_width)
                {
                    continue;
                }
            }
            if (y_width < global_strategy_set[i].range.min_y_width)
            {
                continue;
            }
            if (global_strategy_set[i].range.max_y_width != -1)
            {
                if (y_width > global_strategy_set[i].range.max_y_width)
                {
                    continue;
                }
            }
            // 记录符合要求的策略的ID 
            strategy_buff[j] = i;
            ++j;
        }
        return j;
    }

    ////* 根据各个策略的优先级，随机选择一个策略 
    public static int RandSelectStrategy(int[] strategy_list, int n)
    {
        int i;
        DEBUG_MSG("strategy list:\n");
        for (i = 0; i < n; ++i)
        {
            DEBUG_MSG("%d\n", strategy_list[i]);
        }
        i = RandomNumbers.NextNumber() % n;
        DEBUG_MSG("select strategy: %d\n", i);
        return strategy_list[i];
    }

    public static void GamePlayer_Standby(GamePlayer_ player)
    {
        if (player.state == (int)GamePlayerState.STATE_LEFTRUN || player.state == (int)GamePlayerState.STATE_RIGHTRUN)
        {
            GamePlayer_StopRun(player);
        }
        player.control.a_attack = FALSE;
        player.control.b_attack = FALSE;
        player.control.left_motion = FALSE;
        player.control.right_motion = FALSE;
        player.control.up_motion = FALSE;
        player.control.down_motion = FALSE;
        player.control.run = FALSE;
        GamePlayer_ChangeState(player, (int)GamePlayerState.STATE_STANCE);
    }

    //* 执行策略 
    public static void ExecuteStrategy(GamePlayer_ player)
    {
        int action_type;
        GamePlayer_ target;
        AIStrategy_ p_strategy;
        int x_width=0;
        int y_width=0;
        int n;

        target = GamePlayer_GetTarget(player);
        if (target == null)
        {
            action_type = (int)(int)AIActionType.ai_action_type_none;
        }
        else
        {
            GamePlayer_GetDistance(player, target, ref x_width, ref y_width);
            p_strategy = global_strategy_set[player.ai_data.strategy_id];
            action_type = p_strategy.action[player.ai_data.action_num].action_type;
        }
        switch (action_type)
        {
            case (int)AIActionType.ai_action_type_wait:
                break;
            case (int)AIActionType.ai_action_type_none:
                GamePlayer_Standby(player);
                DEBUG_MSG("ai_action_type_none\n");
                break;
            case (int)AIActionType.ai_action_type_run_close:
                player.control.run = TRUE;
                if (x_width > 0)
                {
                    player.control.left_motion = TRUE;
                    player.control.right_motion = FALSE;
                }
                else
                {
                    player.control.left_motion = FALSE;
                    player.control.right_motion = TRUE;
                }
                if (y_width > DefineConstantsGame_AI.GLOBAL_Y_WIDTH / 2 - 2)
                {
                    player.control.up_motion = TRUE;
                    player.control.down_motion = FALSE;
                }
                else if (y_width < -(DefineConstantsGame_AI.GLOBAL_Y_WIDTH / 2 - 2))
                {
                    player.control.up_motion = FALSE;
                    player.control.down_motion = TRUE;
                }
                else
                {
                    player.control.up_motion = FALSE;
                    player.control.down_motion = FALSE;
                }
                DEBUG_MSG("ai_action_type_run_close\n");
                break;
            case (int)AIActionType.ai_action_type_walk_close:
                player.control.run = FALSE;
                if (x_width > 10)
                {
                    player.control.left_motion = TRUE;
                    player.control.right_motion = FALSE;
                }
                else if (x_width < -10)
                {
                    player.control.left_motion = FALSE;
                    player.control.right_motion = TRUE;
                }
                else
                {
                    player.control.left_motion = FALSE;
                    player.control.right_motion = FALSE;
                }
                if (y_width > DefineConstantsGame_AI.GLOBAL_Y_WIDTH / 2 - 2)
                {
                    player.control.up_motion = TRUE;
                    player.control.down_motion = FALSE;
                }
                else if (y_width < -(DefineConstantsGame_AI.GLOBAL_Y_WIDTH / 2 - 2))
                {
                    player.control.up_motion = FALSE;
                    player.control.down_motion = TRUE;
                }
                else
                {
                    player.control.up_motion = FALSE;
                    player.control.down_motion = FALSE;
                }
                DEBUG_MSG("ai_action_type_walk_close\n");
                break;
            case (int)AIActionType.ai_action_type_run_away:
            case (int)AIActionType.ai_action_type_walk_away:
                if (action_type == (int)(int)AIActionType.ai_action_type_walk_away)
                {
                    player.control.run = FALSE;
                    DEBUG_MSG("ai_action_type_walk_away\n");
                }
                else
                {
                    player.control.run = TRUE;
                    DEBUG_MSG("ai_action_type_run_away\n");
                }
                if (x_width < -20)
                {
                    player.control.left_motion = TRUE;
                    player.control.right_motion = FALSE;
                }
                else if (x_width > 20)
                {
                    player.control.left_motion = FALSE;
                    player.control.right_motion = TRUE;
                }
                else
                {
                    // 随机确定X轴移动方向 
                    n = RandomNumbers.NextNumber() % 2;
                    if (n == 0)
                    {
                        player.control.left_motion = TRUE;
                        player.control.right_motion = FALSE;
                    }
                    else
                    {
                        player.control.left_motion = FALSE;
                        player.control.right_motion = TRUE;
                    }
                }
                // 随机确定Y轴移动方向 
                n = RandomNumbers.NextNumber() % 3;
                if (n == 0)
                {
                    player.control.up_motion = FALSE;
                    player.control.down_motion = FALSE;
                }
                else if (n == 1)
                {
                    player.control.up_motion = FALSE;
                    player.control.down_motion = TRUE;
                }
                else
                {
                    player.control.up_motion = TRUE;
                    player.control.down_motion = FALSE;
                }
                break;
            case (int)AIActionType.ai_action_type_observe:
                player.control.left_motion = FALSE;
                player.control.right_motion = FALSE;
                player.control.up_motion = FALSE;
                player.control.down_motion = FALSE;
                if (!player.lock_action && PlayerCanChangeOriented(player.state))
                {
                    if (x_width < 0)
                    {
                        GamePlayer_SetRightOriented(player);
                    }
                    else if (x_width > 0)
                    {
                        GamePlayer_SetLeftOriented(player);
                    }
                }
                // 如果能够自主活动 
                if (PlayerCanReady(player.state))
                {
                    GamePlayer_SetReady(player);
                }
                DEBUG_MSG("ai_action_type_observe\n");
                break;
            case (int)AIActionType.ai_action_type_stop_run:
                DEBUG_MSG("ai_action_type_stop_run\n");
                GamePlayer_StopRun(player);
                break;
            case (int)AIActionType.ai_action_type_a_attack:
                if (PlayerCanChangeOriented(player.state))
                {
                    if (x_width < 0)
                    {
                        GamePlayer_SetRightOriented(player);
                    }
                    else if (x_width > 0)
                    {
                        GamePlayer_SetLeftOriented(player);
                    }
                }
                player.control.a_attack = TRUE;
                DEBUG_MSG("ai_action_type_a_attack\n");
                break;
            case (int)AIActionType.ai_action_type_b_attack:
                if (PlayerCanChangeOriented(player.state))
                {
                    if (x_width < 0)
                    {
                        GamePlayer_SetRightOriented(player);
                    }
                    else if (x_width > 0)
                    {
                        GamePlayer_SetLeftOriented(player);
                    }
                }
                player.control.b_attack = TRUE;
                DEBUG_MSG("ai_action_type_b_attack\n");
                break;
            case (int)AIActionType.ai_action_type_jump:
                player.control.jump = TRUE;
                DEBUG_MSG("ai_action_type_jump\n");
                break;
            case (int)AIActionType.ai_action_type_down:
                player.control.down_motion = TRUE;
                DEBUG_MSG("ai_action_type_down\n");
                break;
            case (int)AIActionType.ai_action_type_defense:
                player.control.defense = TRUE;
                break;
            case (int)AIActionType.ai_action_type_stop_defense:
                player.control.defense = FALSE;
                break;
            default:
                break;
        }
    }

    //* 检查是否还能继续靠近目标 
    public static LCUI_BOOL CanCloseTarget(GamePlayer_ player)
    {
        int action_type;
        GamePlayer_ target;
        AIStrategy_ p_strategy;
        int x_width=0;
        int y_width=0;

        p_strategy = global_strategy_set[player.ai_data.strategy_id];
        action_type = p_strategy.action[player.ai_data.action_num].action_type;
        if (action_type != (int)(int)AIActionType.ai_action_type_run_close)
        {
            return TRUE;
        }
        target = GamePlayer_GetTarget(player);
        if (target == null)
        {
            return FALSE;
        }
        GamePlayer_GetDistance(player, target, ref x_width, ref y_width);
        p_strategy = global_strategy_set[player.ai_data.strategy_id];
        if (player.state == (int)GamePlayerState.STATE_LEFTRUN)
        {
            if (x_width < 0)
            {
                DEBUG_MSG("left run, x_width: %d\n", x_width);
                GamePlayer_StopRun(player);
                return FALSE;
            }
        }
        else if (player.state == (int)GamePlayerState.STATE_RIGHTRUN)
        {
            if (x_width > 0)
            {
                GamePlayer_StopRun(player);
                DEBUG_MSG("right run, x_width: %d\n", x_width);
                return FALSE;
            }
        }
        return TRUE;
    }

    //* 将游戏玩家交给AI控制 
    public static void GameAI_Control(int battle_id, int player_id)
    {
        GamePlayer_ self;
        GamePlayer_ target;
        int x_width=0;
        int y_width=0;
        int n;
        int[] strategy_buff = new int[10];

        self = GameBattle_GetPlayer(battle_id, player_id);
        // 获取自己的目标 
        target = GamePlayer_GetTarget(self);
        if (target == null)
        {
            return;
        }
        // 检测与目标的距离 
        if (!GamePlayer_GetDistance(self, target, ref x_width, ref y_width))
        {
            return;
        }
        DEBUG_MSG("x_width: %d\n", x_width);
        //如果当前条件不满足当前策略 
        if (StrategyIsValid(self.ai_data, target.state, x_width, y_width)  && CanCloseTarget(self))
        {
            // 检查当前动作是否超时 
            DEBUG_MSG("action: %d\n", self.ai_data.action_num);
            if (StrategyActionIsTimeOut(self.ai_data) )
            {
                DEBUG_MSG("timeout\n");
                ++self.ai_data.action_num;
                self.ai_data.start_time = (int)LCUI_GetTickCount();
                ExecuteStrategy(self);
            }
            return;
        }
        DEBUG_MSG("strategy not valid\n");
        // 根据当前条件筛选出候选策略 
        n = FilterStrategy(strategy_buff, 10, self.state, target.state, x_width, y_width);
        DEBUG_MSG("n = %d\n", n);
        if (n <= 0)
        {
            GamePlayer_Standby(self);
            return;
        }
        // 在候选策略中随机抽选一个策略 
        n = RandSelectStrategy(strategy_buff, n);
        self.ai_data.action_num = 0;
        self.ai_data.strategy_id = n;
        DEBUG_MSG("strategy_id = %d\n", n);
        self.ai_data.start_time = LCUI_GetTickCount();
        // 执行这个策略 
        ExecuteStrategy(self);
    }
}
// ****************************************************************************
// * Punch And Kick -- a simple 2D Fighting Game.
// *
// * Copyright (C) 2013 by
// * Liu Chao
// *
// * This file is part of the Punch And Kick project, and may only be used,
// * modified, and distributed under the terms of the GPLv2.
// *
// * (GPLv2 is abbreviation of GNU General Public License Version 2)
// *
// * By continuing to use, modify, or distribute this file you indicate that you
// * have read the license and understand and accept it fully.
// *
// * The Punch And Kick project is distributed in the hope that it will be
// * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GPL v2 for
// * more details.
// *
// * You should have received a copy of the GPLv2 along with this file. It is
// * usually in the LICENSE.TXT file, If not, see <http://www.gnu.org/licenses/>.
// * **************************************************************************

// ****************************************************************************
// * Punch And Kick -- 一个普通的2D格斗游戏
// *
// * 版权所有 (C) 2013 归属于
// * 刘超
// *
// * 这个文件是 Punch And Kick 项目的一部分，并且只可以根据GPLv2许可协议来使用、
// * 更改和发布。
// *
// * (GPLv2 是 GNU通用公共许可证第二版 的英文缩写)
// *
// * 继续使用、修改或发布本文件，表明您已经阅读并完全理解和接受这个许可协议。
// *
// * Punch And Kick 项目是基于技术交流目的而加以散布的，但不负任何担保责任，例
// * 如：稳定性、可玩性、趣味性等的担保，甚至没有适销性或特定用途的隐含担保，详
// * 情请参照GPLv2许可协议。
// *
// * 您应已收到附随于本文件的GPLv2许可协议的副本，它通常在LICENSE.TXT文件中，如果
// * 没有，请查看：<http://www.gnu.org/licenses/>.
// * **************************************************************************



//C++ TO C# CONVERTER NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define RANGE_MAX -1
//#define RANGE_MAX
//#define MAX_STRATEGY_NUM
//#define MAX_ACTION_NUM_AlternateDefinition1
//#define MAX_ACTION_NUM

public enum AIAIActionType: int
{
	ai_action_type_none,
	ai_action_type_wait,
	ai_action_type_run_close, //*< 跑步靠近目标 
	ai_action_type_walk_close, //*< 步行靠近目标 
	ai_action_type_run_away, //*< 跑步远离目标 
	ai_action_type_walk_away, //*< 步行远离目标 
	ai_action_type_observe, //*< 观察目标 
	ai_action_type_stop_run, //*< 停止奔跑 
	ai_action_type_a_attack, //*< A攻击 
	ai_action_type_b_attack, //*< B攻击 
	ai_action_type_jump, //*< 跳跃 
	ai_action_type_defense, //*< 防御 
	ai_action_type_stop_defense, //*< 停止防御 
	ai_action_type_down
}

//* 距离范围 
public class DistanceRange_
{
	public int min_x_width;
	public int max_x_width;
	public int min_y_width;
	public int max_y_width;

    public DistanceRange_(int v1, int v2, int v3, int v4)
    {
        this.min_x_width = v1;
        this.max_x_width = v2;
        this.min_y_width = v3;
        this.max_y_width = v4;
    }
}

public class AIActionData_
{
	public LCUI_BOOL enable = new LCUI_BOOL(); //*< 该动作是否启用 
	public uint time; //*< 切换至下个动作前需要等待的时间(ms) 
	public int action_type; //*< 动作类型 

    public AIActionData_(LCUI_BOOL tRUE, int Time, int ai_action_type)
    {
        enable = tRUE;
        time = (uint)Time;
        action_type= ai_action_type;
    }
}

//* AI的对战策略 
public class AIStrategy_
{
	public int priority; //*< 优先级，-20至20，从高到低 
	public delegate LCUI_BOOL self_stateDelegate(int NamelessParameter); //*< 回调函数，用于检测自身的状态是否符合要求 
	//public self_stateDelegate self_state;
    public Func<int, LCUI_BOOL> self_state;
    public delegate LCUI_BOOL target_stateDelegate(int NamelessParameter); //*< 回调函数，用于检测对方的状态是否符合要求 
	//public target_stateDelegate target_state;
    public Func<int, LCUI_BOOL> target_state;
    public DistanceRange_ range;//= new DistanceRange_(); //*< 与目标的距离范围 
    public AIActionData_[] action;//= new AIActionData_[DefineConstantsGame_AI.MAX_ACTION_NUM]; //*< 该策略中用到的连续动作 

    public AIStrategy_(int v, Func<int, LCUI_BOOL> canAction, Func<int, LCUI_BOOL> playerWillNormalAttack, DistanceRange_ distanceRange_, AIActionData_[] aIActionData_s)
    {
        priority = v;
        self_state= canAction;
        target_state = playerWillNormalAttack;
        range = distanceRange_;
        action = aIActionData_s;
    }
}

//* 随机想法 
public class RandIdea_
{
	public int id; //*< 该想法的标识号 
	public int probability; //*< 该想法出现的概率，取值范围为0(0.0%)至10000(100%) 
}

//----------------------------------------------------------------------------------------
//	Copyright © 2006 - 2009 Tangible Software Solutions Inc.
//	This class can be used by anyone provided that the copyright notice remains intact.
//
//	This class provides the ability to simulate the behavior of the C/C++ functions for 
//	generating random numbers, using the .NET Framework System.Random class.
//	'rand' converts to the parameterless overload of NextNumber
//	'random' converts to the single-parameter overload of NextNumber
//	'randomize' converts to the parameterless overload of Seed
//	'srand' converts to the single-parameter overload of Seed
//----------------------------------------------------------------------------------------
internal static class RandomNumbers
{
    private static System.Random r;

    internal static int NextNumber()
    {
        if (r == null)
            Seed();

        return r.Next();
    }

    internal static int NextNumber(int ceiling)
    {
        if (r == null)
            Seed();

        return r.Next(ceiling);
    }

    internal static void Seed()
    {
        r = new System.Random();
    }

    internal static void Seed(int seed)
    {
        r = new System.Random(seed);
    }
}

public struct GameAI_Data_
{
	public int strategy_id;        /**< 策略的ID */
	public int action_num;         /**< 当前正执行的动作序号 */
	public int start_time;         /**< 动作开始时的时间 */
	public int target_id;          /**< 目标角色的ID */
	public int target_update_time; /**< 目标更新时间 */
}